<!-- 调控管家--调控设置 -->
<template>
    <div class="t-ctn">
        <div style="text-align: left;margin-top: 39px" class="filrst">
            <label style="color: #cee1f3;font-size: 16px;width: 101px;display: inline-block;padding-left: 46px;">调控目标</label>
            <el-select v-model="formCheckCfg.target" clearable>
                <el-option
                    v-for="(item,index) in typeOptions"
                    :key="index"
                    :label="item"
                    :value="item">
                </el-option>
            </el-select>
        </div>
        <el-form
            ref="formCheckCfg"
            label-width="100px"
            :inline="true"
            label-position="left"
            :model="formCheckCfg">

            <el-form-item prop="valueName" label="热力公司" style="margin-right: 107px">
                <el-select v-model="formCheckCfg.companyId" @change="showSystems" clearable >
                    <el-option
                        v-for="(item,index) in companys"
                        :key="index"
                        :label="item.name"
                        :value="item.id">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item prop="valueName" label="供热系统" style="margin-right: 107px">
                <el-select v-model="formCheckCfg.systemId"  @change="showSources" clearable >
                    <el-option
                        v-for="(item,index) in systems"
                        :key="index"
                        :label="item.name"
                        :value="item.id">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item prop="valueName" label="热源" style="margin-right: 107px">
                <el-select v-model="formCheckCfg.sourceId" clearable >
                    <el-option
                        v-for="(item,index) in sources"
                        :key="index"
                        :label="item.name"
                        :value="item.id">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item prop="valueName" label="换热站" style="margin-right: 107px" >
                <el-select v-model="formCheckCfg.stationId" @change="showUnits" clearable >
                    <el-option
                        v-for="(item,index) in stations"
                        :key="index"
                        :label="item.name"
                        :value="item.id">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item prop="valueName" label="机组" style="margin-right: 107px" >
                <el-select v-model="formCheckCfg.unitId" @change="showHalls" clearable >
                    <el-option
                        v-for="(item,index) in units"
                        :key="index"
                        :label="item.name"
                        :value="item.id">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item prop="valueName" label="单元" style="margin-right: 107px" >
                <el-select v-model="formCheckCfg.hallId" @change="showHouses" clearable >
                    <el-option
                        v-for="(item,index) in halls"
                        :key="index"
                        :label="item.name"
                        :value="item.id">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item prop="valueName" label="户" style="margin-right: 107px">
                <el-select v-model="formCheckCfg.houseId" clearable >
                    <el-option
                        v-for="(item,index) in houses"
                        :key="index"
                        :label="item.name"
                        :value="item.id">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="handleDataList">确定</el-button>
                <el-button type="primary" @click="handleReset">重置</el-button>
                <el-button
                    v-if="curName === '机组'"
                    :type="roles[0].roleCode === 'Query_Data' ? 'info' : 'primary'"
                    :disabled="roles[0].roleCode === 'Query_Data'"
                    @click="handlSet"
                >阈值设置</el-button>
            </el-form-item>
        </el-form>
        <div class="line"></div>
        <div class="s-n-ctn-main" style="position: relative">
            <div style="height:100%" ref="tableWrapper">
                <el-table
                    v-if="tableData.length > 0 && curName === '热源'"
                    ref="singleTable"
                    :data="tableData"
                    stripe
                    :height="tableH"
                    style="width: 100%;background-color: transparent;overflow: auto">
                    <!-- 热源 -->
                       <el-table-column
                           type="selection"
                           width="150"
                       />

                    <el-table-column
                        prop="sourceName"
                        show-overflow-tooltip
                        label="名称">
                    </el-table-column>
                    <el-table-column
                        show-overflow-tooltip
                        label="类型">
                        <span>热源</span>
                    </el-table-column>
                    <el-table-column
                        prop="tt011Value"
                        show-overflow-tooltip
                        label="供温">
                    </el-table-column>
                    <el-table-column
                        prop="tt021Value"
                        show-overflow-tooltip
                        label="回温">
                    </el-table-column>
                    <el-table-column
                        prop="ft021Value"
                        show-overflow-tooltip
                        label="流量">
                    </el-table-column>
                    <el-table-column label="当前状态">
                        <template slot-scope="scope">
                            <span>{{scope.row.inControl === 0 ? '手动' : '自动'}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="timestamp"
                        show-overflow-tooltip
                        label="更新时间">
                    </el-table-column>
                    <el-table-column label="阈值设置" width="100px" fixed="right">
                        <template slot-scope="scope">
                            <el-button
                                size="mini"
                                type="primary"
                                @click.native.stop="handleSettingEr( scope.row,4)">设置</el-button>
                        </template>
                    </el-table-column>

                </el-table>
                <el-table
                    v-if="tableData1.length > 0 && curName === '机组'"
                    ref="singleTable"
                    :data="tableData1"
                    stripe
                    :height="tableH"
                    @selection-change="handleSelectionChange"
                    style="width: 100%;background-color: transparent;overflow: auto">
                    <!-- jizu  -->
                    <el-table-column
                        type="selection"
                        width="150"
                    />

                        <el-table-column
                            prop="unitName"
                            label="名称">
                        </el-table-column>
                        <el-table-column
                            label="类型">
                            <span>机组</span>
                        </el-table-column>
                        <el-table-column
                            prop="stationName"
                            label="所属换热站">
                        </el-table-column>
                        <el-table-column
                            prop="tt211Value"
                            label="二网供温">
                        </el-table-column>
                        <el-table-column
                            prop="tt221Value"
                            label="二网回温">
                        </el-table-column>
                        <el-table-column
                            prop="ft221Value"
                            label="二网流量">
                        </el-table-column>
                        <el-table-column label="当前状态" width="100">
                            <template slot-scope="scope">
                                <span>{{scope.row.inControl === 0 ? '手动' : '自动'}}</span>
                            </template>
                        </el-table-column>
                    <el-table-column label="校准值" >
                        <template slot-scope="scope">
                            <span :class="scope.row.calibration && scope.row.calibration > 0 ? 'jiao_red' : (scope.row.calibration && scope.row.calibration <0 ? 'jiao_green' :'' )" style="margin-right: 10px">{{scope.row.calibration}}</span>
                            <el-button
                                size="mini"
                                :type="roles[0].roleCode === 'Query_Data' ? 'info' : 'primary'"
                                :disabled="roles[0].roleCode === 'Query_Data'"
                                @click.native.stop="handleSettingEr( scope.row,1)">修改</el-button>
                        </template>
                    </el-table-column>
                        <!-- 手动的时候才显示 -->
                        <el-table-column label="二供温设置">
                            <template slot-scope="scope">
                                <template v-if="scope.row.inControl === 0">
                                    <el-button
                                        size="mini"
                                        :type="roles[0].roleCode === 'Query_Data' ? 'info' : 'primary'"
                                        :disabled="roles[0].roleCode === 'Query_Data'"
                                        @click.native.stop="handleSettingEr( scope.row,2)">二网供水温度设置</el-button>
                                </template>
                            </template>
                        </el-table-column>
                        <el-table-column
                            prop="timestamp"
                            label="更新时间">
                        </el-table-column>
                    <el-table-column label="阈值设置" width="100px" fixed="right">
                        <template slot-scope="scope">
                            <el-button
                                size="mini"
                                :type="roles[0].roleCode === 'Query_Data' ? 'info' : 'primary'"
                                :disabled="roles[0].roleCode === 'Query_Data'"
                                @click.native.stop="handleSettingEr( scope.row,4)">设置</el-button>
                        </template>
                    </el-table-column>

                </el-table>
                <el-table
                    v-if="tableData2.length > 0 && curName === '单元'"
                    ref="singleTable"
                    :data="tableData2"
                    stripe
                    :height="tableH"
                    style="width: 100%;background-color: transparent;overflow: auto">
                    <!-- 热源 -->
                       <el-table-column
                           type="selection"
                           width="150"
                       />

                        <el-table-column
                            prop="hallName"
                            show-overflow-tooltip
                            label="名称">
                        </el-table-column>
                        <el-table-column
                            show-overflow-tooltip
                            label="类型">
                            <template slot-scope="scope">
                                <span>单元</span>
                            </template>
                        </el-table-column>
                        <el-table-column
                            prop="stationName"
                            show-overflow-tooltip
                            label="所属换热站">
                        </el-table-column>
                        <el-table-column
                            prop="unitName"
                            show-overflow-tooltip
                            label="所属机组">
                        </el-table-column>
                        <el-table-column
                            prop="covValue"
                            show-overflow-tooltip
                            label="阀门开度">
                        </el-table-column>
                        <el-table-column
                            prop="tt221Value"
                            show-overflow-tooltip
                            label="回温">
                        </el-table-column>
                        <el-table-column label="当前状态">
                            <template slot-scope="scope">
                                <span>{{scope.row.inControl === 0 ? '手动' : '自动'}}</span>
                            </template>
                        </el-table-column>

                        <el-table-column
                            prop="timestamp"
                            show-overflow-tooltip
                            label="更新时间">
                        </el-table-column>

                    <el-table-column label="阈值设置" width="100px" fixed="right">
                        <template slot-scope="scope">
                            <el-button
                                size="mini"
                                :type="roles[0].roleCode === 'Query_Data' ? 'info' : 'primary'"
                                :disabled="roles[0].roleCode === 'Query_Data'"
                                @click.native.stop="handleSettingEr( scope.row,4)">设置</el-button>
                        </template>
                    </el-table-column>

                </el-table>
                <el-table
                    v-if="tableData3.length > 0 && curName === '户'"
                    ref="singleTable"
                    :data="tableData3"
                    stripe
                    :height="tableH"
                    style="width: 100%;background-color: transparent;overflow: auto">
                    <!-- 热源 -->
                       <el-table-column
                           type="selection"
                           width="150"
                       />
                        <el-table-column
                            prop="houseName"
                            show-overflow-tooltip
                            label="名称">
                        </el-table-column>
                        <el-table-column
                            show-overflow-tooltip
                            label="类型">
                            <template slot-scope="scope">
                                <span>户</span>
                            </template>
                        </el-table-column>
                        <el-table-column
                            prop="stationName"
                            show-overflow-tooltip
                            label="所属换热站">
                        </el-table-column>
                        <el-table-column
                            prop="unitName"
                            show-overflow-tooltip
                            label="所属机组">
                        </el-table-column>
                        <el-table-column
                            prop="hallName"
                            show-overflow-tooltip
                            label="所属单元">
                        </el-table-column>
                        <el-table-column
                            prop="covValue"
                            show-overflow-tooltip
                            label="阀门开度">
                        </el-table-column>
                        <el-table-column
                            prop="tt421Value"
                            show-overflow-tooltip
                            label="回温">
                        </el-table-column>
                        <el-table-column
                            prop="tt401Value"
                            show-overflow-tooltip
                            label="室温">
                        </el-table-column>
                        <el-table-column label="当前状态">
                            <template slot-scope="scope">
                                <span>{{scope.row.inControl === 0 || scope.row.inControl === null ? '手动' : '自动'}}</span>
                            </template>
                        </el-table-column>

                        <el-table-column
                            prop="timestamp"
                            show-overflow-tooltip
                            label="更新时间">
                        </el-table-column>
                    <el-table-column label="阈值设置" width="100px" fixed="right">
                        <template slot-scope="scope">
                            <el-button
                                size="mini"
                                type="primary"
                                @click.native.stop="handleSettingEr( scope.row,4)">设置</el-button>
                        </template>
                    </el-table-column>

                </el-table>
            </div>
            <!-- 设计上没有分页 -->
            <Pagination
                v-if="tableData.length > 0 && curName === '热源'"
                :total="total"
                :page.sync="formCheckCfg.pageNo"
                :limit.sync="formCheckCfg.pageSize"
                style="margin-top: 5px"
                @pagination="handleDataList"
            />
            <Pagination
                v-if="tableData1.length > 0 && curName === '机组'"
                :total="total1"
                :page.sync="formCheckCfg.pageNo"
                :limit.sync="formCheckCfg.pageSize"
                style="margin-top: 5px"
                @pagination="handleDataList"
            />
            <Pagination
                v-if="tableData2.length > 0 && curName === '单元'"
                :total="total2"
                :page.sync="formCheckCfg.pageNo"
                :limit.sync="formCheckCfg.pageSize"
                style="margin-top: 5px"
                @pagination="handleDataList"
            />
            <Pagination
                v-if="tableData3.length > 0 && curName === '户'"
                :total="total3"
                :page.sync="formCheckCfg.pageNo"
                :limit.sync="formCheckCfg.pageSize"
                style="margin-top: 5px"
                @pagination="handleDataList"
            />
        </div>
        <!-- 设置信息 -->
        <el-dialog v-if="openCfg" :visible.sync="openCfg" custom-class="check" :title="`${curName}阈值设置`" width="500px">
            <div class="tabs" style="justify-content: start;">
                <!--<span :class="['tab-item',{'active':currentTab ===1}]" @click="changeTypeTab(1)"></span>
                <span :class="['tab-item',{'active':currentTab ===2}]" @click="changeTypeTab(2)"></span>-->
                <el-switch
                    v-model="editData.inControl"
                    active-color="rgba(3,195,250,1)"
                    inactive-color="rgba(3,195,250,1)"
                    active-text="手动控制"
                    :active-value="0"
                    :inactive-value="1"
                    @change="changeTypeTab"
                    inactive-text="自动控制"></el-switch>
            </div>
            <!-- 热源 -->
            <el-form
                v-if="curName === '热源'"
                ref="editData"
                label-width="100px"
                :model="editData">
                <!--<el-form-item label="调控目标">
                    <el-input
                        v-model="editData.target"
                        placeholder="调控目标"
                        clearable>
                    </el-input>
                </el-form-item>-->
                <el-form-item label="流量下限"><!--
                    <el-input-number v-model="editData.flowMin" :min="0" :max="100" label="流量下限"></el-input-number>-->
                    <el-input
                        v-model="editData.flowMin"
                        :disabled="disabled"
                        clearable>
                    </el-input>
                </el-form-item>
                <el-form-item label="流量上限"><!--
                    <el-input-number v-model="editData.flowMax" :min="0" :max="100" label="流量上限"></el-input-number>-->
                    <el-input
                        v-model="editData.flowMax"
                        :disabled="disabled"
                        clearable>
                    </el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="handleSave('热源')">保存</el-button>
                </el-form-item>
            </el-form>
            <!-- 机组 -->
            <el-form
                v-if="curName === '机组'"
                ref="editData"
                label-width="140px"
                :model="editData">
                <el-form-item label="二供温上限"><!--
                    <el-input-number v-model="editData.gotempMax" :min="0" :max="100" label="二供温上限"></el-input-number>-->
                    <el-input
                        v-model="editData.gotempMax"
                        :disabled="disabled"
                        clearable>
                    </el-input>
                </el-form-item>
                <el-form-item label="二供温下限"><!--
                    <el-input-number v-model="editData.gotempMin" :min="0" :max="100" label="二供温下限"></el-input-number>-->
                    <el-input
                        v-model="editData.gotempMin"
                        :disabled="disabled"
                        clearable>
                    </el-input>
                </el-form-item>
                <el-form-item label="二供温浮动上限℃">
                    <el-input
                        v-model="editData.gotempChangeMax"
                        :disabled="disabled"
                        clearable>
                    </el-input>
                </el-form-item><!--
                <el-form-item label="调控目标">
                    <el-input
                        v-model="editData.target"
                        clearable>
                    </el-input>
                </el-form-item>-->
                <el-form-item label="一次流量下限"><!--
                    <el-input-number v-model="editData.oneFlowMin" :min="0" :max="100" label="流量下限"></el-input-number>-->
                    <el-input
                        v-model="editData.oneFlowMin"
                        :disabled="disabled"
                        clearable>
                    </el-input>
                </el-form-item>
                <el-form-item label="一次流量上限"><!--
                    <el-input-number v-model="editData.oneFlowMax" :min="0" :max="100" label="流量上限"></el-input-number>-->
                    <el-input
                        v-model="editData.oneFlowMax"
                        :disabled="disabled"
                        clearable>
                    </el-input>
                </el-form-item>
                <el-form-item label="二次压力上限"><!--
                    <el-input-number v-model="editData.pt211SetMax" :min="0" :max="100" label="压力上限"></el-input-number>-->
                    <el-input
                        v-model="editData.pt211SetMax"
                        :disabled="true"
                        clearable>
                    </el-input>
                </el-form-item>
                <el-form-item label="二次压力下限"><!--
                    <el-input-number v-model="editData.pt211SetMin" :min="0" :max="100" label="压力下限"></el-input-number>-->
                    <el-input
                        v-model="editData.pt211SetMin"
                        :disabled="true"
                        clearable>
                    </el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="handleSave('机组')">保存</el-button>
                </el-form-item>
            </el-form>
            <!-- 单元 -->
            <el-form
                v-if="curName === '单元'"
                ref="editData"
                label-width="100px"
                :model="editData"><!--
                <el-form-item label="调控目标">
                    <el-input
                        v-model="editData.target"
                        placeholder="调控目标"
                        clearable>
                    </el-input>
                </el-form-item>-->
                <el-form-item label="回水温度下限"><!--
                    <el-input-number v-model="editData.backwaterMin" :min="0" :max="100" label="回水温度下限"></el-input-number>-->
                    <el-input
                        v-model="editData.backwaterMin"
                        :disabled="disabled"
                        clearable>
                    </el-input>
                </el-form-item>
                <el-form-item label="阀门开度下限"><!--
                    <el-input-number v-model="editData.valveMin" :min="0" :max="100" label="阀门开度下限"></el-input-number>-->
                    <el-input
                        v-model="editData.valveMin"
                        :disabled="disabled"
                        clearable>
                    </el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="handleSave('单元')">保存</el-button>
                </el-form-item>
            </el-form>
            <!-- 户 -->
            <el-form
                v-if="curName === '户'"
                ref="editData"
                label-width="100px"
                :model="editData">
                <!--<el-form-item label="调控目标">
                    <el-input
                        v-model="editData.target"
                        placeholder="调控目标"
                        clearable>
                    </el-input>
                </el-form-item>-->
                <el-form-item label="回水温度下限"><!--
                    <el-input-number v-model="editData.backwaterMin" :min="0" :max="100" label="回水温度下限"></el-input-number>-->
                    <el-input
                        v-model="editData.backwaterMin"
                        :disabled="disabled"
                        clearable>
                    </el-input>
                </el-form-item>
                <el-form-item label="阀门开度下限"><!--
                    <el-input-number v-model="editData.valveMin" :min="0" :max="100" label="阀门开度下限"></el-input-number>-->
                    <el-input
                        v-model="editData.valveMin"
                        :disabled="disabled"
                        clearable>
                    </el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="handleSave('户')">保存</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>
<!-- 密码-->
        <el-dialog v-if="openCfgEr" :visible.sync="openCfgEr" custom-class="check" title="密码验证" width="380px">
            <el-form
                label-width="100px"
                :model="editDataV">
                <el-form-item label="密码">
                    <el-input
                        v-model="editDataV.psd"
                        placeholder="输入密码"
                        clearable>
                    </el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="handleSaveEr()">确定</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>

<!-- 二网供温 -->
        <el-dialog v-if="openCfgErS" :visible.sync="openCfgErS" custom-class="check" :title="``" width="400px">
            <el-form
                label-width="130px"
                :model="editDataErS">
                <el-form-item label="二次供水温度">
                    <el-input
                        v-model="editDataErS.twotemp"
                        placeholder="二次供水温度"
                        clearable>
                    </el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="handleSaveErS()">确定</el-button>
                    <el-button type="primary" @click="openCfgErS = false">取消</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>
<!--   校准值     -->
        <el-dialog v-if="openCfgErJ" :visible.sync="openCfgErJ" custom-class="check" title="修改校准值" width="400px">
            <el-form
                label-width="130px"
                :model="editDataErJ">
                <el-form-item label="校准值">
                    <el-input
                        v-model="editDataErJ.calibration"
                        @input="getInput"
                        clearable>
                    </el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="handleSaveErJ()">确定</el-button>
                    <el-button type="primary" @click="openCfgErJ = false">取消</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>
    </div>
</template>

<script>
     import API from "../../../request/api";
     import {sysTime} from "../../../utils/utils";
     import Pagination from "../../../components/page";

    export default {
        name: 'RegulationSet',
        components: {
            Pagination
        },
        computed: {
            roles(){
                return this.$store.state.roles
            }
        },
        data() {
            return {
                openCfgErS:false,
                openCfgErJ:false,
                editDataErS:{},
                editDataErJ:{},
                tableH:0,
                disabled: false,
                currentTab: 1,
                formCheckCfg:{
                    companyId:'',
                    pageNo:1,
                    pageSize:10,
                    target:'',
                    hallId:'',
                    houseId:'',
                    sourceId:'',
                    stationId:'',
                    systemId:'',
                    unitId:'',
                }, //顶部表单
                currentTabCfg: 1,
                total: 0,
                total1: 0,
                total2: 0,
                total3: 0,
                tableData: [],
                tableData1: [],
                tableData2: [],
                tableData3: [],
                typeOptions:[], // 调控目标
                openCfg: false, // 设置弹窗
                editData: {},
                tree:[],
                isShowTree:false,
                defaultProps: {
                    children: 'children',
                    label: 'name'
                },
                curName:'', //当前设置的类型
                companys:[],
                systems:[],
                sources:[],
                stations:[],
                units:[],
                halls:[],
                houses:[],
                company:'',
                openCfgEr:false,
                editDataV:{},
                multipleSelection: [],
                levelType:1, // 默认热企
                diagType: 0 // 弹窗类型
            };
        },
        mounted() {
            // 获取调控目标
            this.getTargetList()
            // 获取组织树
            this.getTree();
            this.fetTableHeight();
        },
        watch: {

        },
        methods: {
            handleSelectionChange(val) {
                this.multipleSelection = val;
            },
            // 全部设置
            handlSet(){
                if(this.multipleSelection.length >0){
                    let row = {
                        unitId:this.multipleSelection[0].unitId
                    }
                    this.handleSettingEr(row,3)
                }else{
                    this.msgWarning('请勾选');
                }

            },
            resetHeight() {
                return new Promise((resolve, reject) => {
                    this.tableH = 0
                    resolve()
                })
            },
            // 设置table高度
            fetTableHeight() {
                this.resetHeight().then(res => {
                    this.tableH = this.$refs.tableWrapper.getBoundingClientRect().height - 20
                })
            },
            // 组织树
            getTree(){
                API.RegulationTree().then(res =>{
                    if(res.code === 0){
                        this.tree = res.result;
                        if(res.result.length > 0){
                            res.result.forEach(item =>{
                                this.companys.push(item)
                            })
                            this.formCheckCfg.companyId = this.companys[0].id

                        }this.showSystems()
                    }else{
                        this.msgWarning(res.message);
                    }
                }).catch( err =>{
                  //  this.msgWarning(err);
                })
            },
            showSystems(res){
                this.tree.forEach(item=>{
                    if(item.id === this.formCheckCfg.companyId && item.children && item.children.length>0){
                        this.systems = item.children
                    }
                })
            },
            showSources(res){
                if(this.systems && this.systems.length > 0){
                    this.systems.forEach(item=>{
                        if(item.id === this.formCheckCfg.systemId){
                            if(item.children && item.children.length>0){
                                item.children.forEach(subItem=>{
                                    if(subItem.level === '3'){
                                        this.stations.push(subItem) // 换热站
                                    }else{
                                        this.sources.push(subItem) // 热源
                                    }
                                })
                            }else{
                                this.sources = []
                                this.stations = []
                            }
                        }
                    })
                }else{
                    this.sources = []
                    this.stations = []
                }
            },
            showUnits(){
                if(this.stations && this.stations.length > 0){
                    this.stations.forEach(item=>{
                        if(item.id === this.formCheckCfg.stationId && item.children && item.children.length>0){
                            if(item.children && item.children.length>0){
                                this.units = item.children
                            }else{
                                this.units = []
                            }

                        }
                    })
                }else{
                    this.units = []
                }
            },
            showHalls(){
                if(this.units && this.units.length > 0){
                    this.units.forEach(item=>{
                        if(item.id === this.formCheckCfg.unitId){

                            if(item.children && item.children.length>0){
                                this.halls = item.children
                            }else{
                                this.halls = []
                            }
                        }
                    })
                }else{
                    this.halls = []
                }
            },
            showHouses(){
                if(this.halls && this.halls.length > 0){
                    this.halls.forEach(item=>{
                        if(item.id === this.formCheckCfg.hallId ){
                            if(item.children && item.children.length>0){
                                this.houses = item.children
                            }else{
                                this.houses = []
                            }
                        }
                    })
                }else{
                    this.houses = []
                }
            },
            changeSTree(){
                this.isShowTree = true;
            },
            selectClass(data){
                this.isShowTree = false;
                this.formCheckCfg.id = data.id;
                this.formCheckCfg.name = data.name;
                /*if(data.level === 1){
                    this.formCheckCfg.name = data.id;
                }*/
                if(data.level === '2'){
                    this.formCheckCfg.systemid = data.id;
                }
                if(data.level === '3'){
                    this.formCheckCfg.stationid = data.id;
                }
                if(data.level === '4'){
                    this.formCheckCfg.unitid = data.id;
                }
                if(data.level === '5'){
                    this.formCheckCfg.hallid = data.id;
                }
                if(data.level === '6'){
                    this.formCheckCfg.houseid = data.id;
                }
                if(data.level === '7'){
                    this.formCheckCfg.sourceid = data.id;
                }
            },
            filterNode(value, data){
                if(!value){
                    return true
                }else {
                    return data.name.indexOf(value) !== -1
                }
            },
            // 获取调控目标
            getTargetList(){
                API.getReTargetList().then(res =>{
                    if(res.code === 0){
                        this.typeOptions = res.result;
                    }else{
                        this.msgWarning(res.message);
                    }
                }).catch( err =>{
                    //this.msgWarning(err);
                })
            },
            // 获取列表
            handleDataList(){
                this.curName = this.formCheckCfg.target
                API.getregulationList(this.formCheckCfg).then(res =>{
                    if(res.code === 200){
                        if(res.result.records.length === 0){
                            return this.msgWarning('无数据');
                        }

                        if(this.formCheckCfg.target === '热源'){
                            this.tableData = res.result.records;
                            this.total = res.result ? res.result.total : 0;
                        }
                        if(this.formCheckCfg.target === '机组'){
                            this.tableData1 = res.result.records;
                            this.total1 = res.result ? res.result.total : 0;
                        }
                        if(this.formCheckCfg.target === '单元'){
                            this.tableData2 = res.result.records;
                            this.total2 = res.result ? res.result.total : 0;
                        }
                        if(this.formCheckCfg.target === '户'){
                            this.tableData3 = res.result.records;
                            this.total3 = res.result ? res.result.total : 0;
                        }
                    }else{
                        this.msgWarning(res.message);
                    }
                }).catch( err =>{
                    //this.msgWarning(err);
                })
            },
            // 重置
            handleReset(){
                this.formCheckCfg.target = '';
                this.formCheckCfg.houseId = '';
                this.formCheckCfg.sourceId = '';
                this.formCheckCfg.stationId = '';
                this.formCheckCfg.systemId = '';
                this.formCheckCfg.unitId = '';
                this.formCheckCfg.hallId = '';
                this.formCheckCfg.pageNo = 1;
                this.formCheckCfg.pageSize = 10;
            },
            changeTypeTab(currentTabCfg){
                this.currentTab = currentTabCfg;
                // 手动和自动都可以编辑
                this.disabled = false
                // 如果是批量设置阈值
                if(this.diagType === 3){
                    let ids = []
                    this.multipleSelection.map(item =>{
                        ids.push(item.unitId)
                    })
                    let data = {
                        ids: ids,
                        inControl: currentTabCfg
                    }
                    API.updateBatchIncontrol(data).then(res =>{
                        if(res.code === 200){
                            this.msgSuccess(res.result)
                        }else{
                            this.msgWarning(res.message);
                        }
                    }).catch( err =>{
                        // this.msgWarning(err);
                    })
                }else{
                    // 如果是单个设置
                    let data = {
                        id : this.editData.id,
                        target:this.editData.target,
                        inControl: currentTabCfg
                    }
                    API.updateIncontrol(data).then(res =>{
                        if(res.code === 200){
                            this.msgSuccess(res.result)
                        }else{
                            this.msgWarning(res.message);
                        }
                    }).catch( err =>{
                        // this.msgWarning(err);
                    })
                }
            },
            handleSettingEr(row,type){
                this.openCfgEr = true;
                this.editDataV = {
                    id:row.unitId,
                    psd:'',
                    target:this.curName
                }
                this.editData = {...row};
                this.diagType = type // 弹窗类型
            },
            // 设置二供温
            handleSaveErS(){
                API.twotemp(this.editDataErS).then(res =>{

                    if(res.code === 200){
                        this.msgSuccess('设置成功');
                        this.openCfgErS = false;
                    }else{
                        this.msgWarning(res.message);
                    }
                }).catch( err =>{
                    // this.msgWarning(err);
                })
            },
            getInput(e){
                let reg = /^[\d\.-]*$/
                if(!reg.test(e)){
                    this.editDataErJ.calibration = e.substr(0,e.length-1)
                }
                if(Math.round( Number(e)) > 5){
                    this.editDataErJ.calibration = 5
                }
                if(Math.round( Number(e)) < -5){
                    this.editDataErJ.calibration = -5
                }
            },
            // 设置下校准值
            handleSaveErJ(){
                API.updateCalibration(this.editDataErJ).then(res =>{
                    if(res.code === 200){
                        this.msgSuccess('设置成功');
                        this.openCfgErJ = false;
                    }else{
                        this.msgWarning(res.message);
                    }
                }).catch( err =>{
                    // this.msgWarning(err);
                })
            },
            // 设置
            handleSetting(){

                if(this.curName === '户'){
                    this.editData.target = '户'
                    this.editData.houseId = this.editData.id
                }
                if(this.curName === '单元'){
                    this.editData.target = '单元'
                    this.editData.id = this.editData.hallId
                }
                if(this.curName === '机组'){
                    this.editData.target = '机组'
                    this.editData.id = this.editData.unitId
                    const that = this

                    API.getRegulaSetUnit({unitId:this.editData.unitId}).then(res =>{
                        if(res.code === 200){

                            that.editData = { ...res.result,...this.editData,}
                            that.openCfg = true;
                        }else{
                            that.msgWarning(res.message);
                        }
                    }).catch( err =>{
                        // this.msgWarning(err);
                    })
                }
                if(this.curName === '热源'){
                    this.editData.target = '热源'
                    this.editData.id = this.editData.sourceId
                }
                // 设置手动或者自动，1表示自动，0或者null表示手动
                if(this.editData.inControl === 1){
                    this.currentTab = 2
                }else{
                    this.currentTab = 1
                    this.editData.inControl = 0
                }
                this.openCfg = true;
            },
            handleSaveEr(){
                API.check(this.editDataV).then(res =>{
                    if(res.code === 200 && res.result.err === 0){
                        // 二网供温设置
                        if(this.diagType === 2){
                            this.openCfgErS = true;
                            this.editDataErS.unitId = this.editDataV.id;
                        }

                        // 校准值
                        if(this.diagType === 1){
                            this.openCfgErJ = true;
                            this.editDataErJ.unitId = this.editDataV.id;
                        }

                        // 批量设置阈值
                        if(this.diagType === 3){
                            this.openCfg = true
                        }
                        // 单个设置阈值
                        if(this.diagType === 4){
                            this.handleSetting()
                        }


                        this.openCfgEr = false;
                    }else{
                        this.msgWarning('验证失败');
                    }
                }).catch( err =>{
                    // this.msgWarning(err);
                })
            },
            // 保存设置信息
            handleSave(name){
                if(name === '户'){
                    API.setHallHouse(this.editData).then(res =>{
                        if(res.code === 200){
                            this.msgSuccess('设置成功');
                            this.openCfg = false;
                            this.handleDataList();
                        }else{
                            this.msgWarning(res.message);
                        }
                    }).catch( err =>{
                       // this.msgWarning(err);
                    })
                }

                if(name === '单元'){
                    API.setHallValve(this.editData).then(res =>{
                        if(res.code === 200){
                            this.msgSuccess('设置成功');
                            this.openCfg = false;
                            this.handleDataList();
                        }else{
                            this.msgWarning(res.message);
                        }
                    }).catch( err =>{
                       // this.msgWarning(err);
                    })
                }

                if(name === '热源'){
                    API.setSourceFlow(this.editData).then(res =>{
                        if(res.code === 200){
                            this.msgSuccess('设置成功');
                            this.openCfg = false;
                            this.handleDataList();
                        }else{
                            this.msgWarning(res.message);
                        }
                    }).catch( err =>{
                       // this.msgWarning(err);
                    })
                }
                if(name === '机组'){
                    this.editData.target = '机组'
                    let aa = []
                    this.multipleSelection.map(item =>{
                        aa.push(item.unitId)
                    })
                    this.editData.ids = aa

                    API.setUnitTemp(this.editData).then(res =>{
                        if(res.code === 200){
                            this.msgSuccess('设置成功');
                            this.openCfg = false;
                            this.handleDataList();
                        }else{
                            this.msgWarning(res.message);
                        }
                    }).catch( err =>{
                      //  this.msgWarning(err);
                    })
                }
            }
        }
    };
</script>

<style lang="scss" type="text/scss" scoped>
    .t-ctn {

        .jiao_red{
            color: #ff3838;
        }

        .jiao_green{
            color: #00ffa1;
        }

        ::v-deep .el-input.is-disabled .el-input__inner{
            background-color: #F5F7FA !important;
            border-color: #E4E7ED !important;
            color: #C0C4CC !important;
        }

        .filrst{

                ::v-deep .el-input__inner{
                    background: rgba(12,255,252,0.16) !important;
                    border: 1px solid rgb(12,255,252) !important;
                }
        }

        .tabs{
            height: 42px !important;
            line-height: 42px !important;
            color: #00e4ff;
            font-size: 16px !important;
            display: flex;
            justify-content: end;

            .tab-item{
                width: 97px !important;
                height: 42px !important;
                background: rgba(12,132,255,0.16);
                border: 1px solid #008aff;
                display: inline-block;
                cursor: pointer;

                &:first-child{
                    border-radius: 5px 0 0 5px !important;
                }
                &:last-child{
                    border-radius: 0 5px 5px 0 !important;
                }

                &.active{
                    background: #2063a8;
                    border: 1px solid #008aff;
                    color: #ffffff;
                }
            }
        }

        .line{
            height: 4px;
            margin-left: 29px;
            margin-right: 37px;
            background: url("../../../assets/common/basi-line.png") no-repeat center/100% 100%;
        }

        >.el-form{
            margin-right: 42px;
            margin-left: 46px;
            margin-top: 22px;
            font-size: 16px;
        }

        .s-n-ctn-main{
            height: calc(100% - 300px);
            margin-top: -30px;
            margin-right: 42px;
            margin-left: 46px;

            .demo-form-inline {
                font-size: 16px;
                text-align: left;

                .sub-tabs {
                    color: #00e4ff;

                    .sub-tab-item {
                        width: 97px;
                        height: 42px;
                        text-align: center;
                        line-height: 42px;
                        border: 1px solid #008aff;
                        display: inline-block;
                        cursor: pointer;

                        &:first-child {
                            border-radius: 5px 0 0 0;
                        }

                        &:last-child {
                            border-radius: 0 5px 0 0;
                        }

                        &.active {
                            background: #156fcb;
                            border: 1px solid #008aff;
                            color: #ffffff;
                        }
                    }
                }
            }

            .el-form{
                width: 100%;
                display: flex;
                justify-content: flex-end;
            }

            .el-table{
                margin-top: 60px;
            }
        }
    }
</style>
